using UnityEngine;

public class AudioManager : MonoBehaviour
{
    public static AudioManager Instance { get; private set;}

    [SerializeField] AudioClip[] birdReadyAudioClips;
    [SerializeField] AudioClip[] birdHitAudioClips;
    [SerializeField] AudioClip[] birdFlyAudioClips;
    [SerializeField] AudioClip[] pigDamageAudioClips;
    [SerializeField] AudioClip[] woodDamageAudioClips;
    [SerializeField] AudioClip[] woodDestroyAudioClips;

    void Awake()
    {
        Instance = this;
    }

    public void PlayBirdReady(Vector3 position)
    {
        this.Play(this.birdReadyAudioClips, position);
    }

    public void PlayBirdHit(Vector3 position)
    {
        this.Play(this.birdHitAudioClips, position);
    }

    public void PlayBirdFly(Vector3 position, float volume = 1.0f)
    {
        this.Play(this.birdFlyAudioClips, position, volume);
    }

    public void PlayPigDamage(Vector3 position, float volume = 1.0f)
    {
        this.Play(this.pigDamageAudioClips, position, volume);
    }
    
    public void PlayWoodDamage(Vector3 position, float volume = 1.0f)
    {
        this.Play(this.woodDamageAudioClips, position, volume);
    }

    public void PlayWoodDestroy(Vector3 position, float volume = 1.0f)
    {
        this.Play(this.woodDestroyAudioClips, position, volume);
    }

    private void Play(AudioClip[] audioClips, Vector3 position, float volume = 1.0f)
    {
        var index = Random.Range(0, audioClips.Length);
        var audioClip = audioClips[index];
        AudioSource.PlayClipAtPoint(audioClip, position, volume);
    }
}
